package com.zerox.interceptor;


import com.zerox.pojo.SysUser;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SysUserInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断是否登录
        SysUser user= (SysUser) request.getSession().getAttribute("loginUser");
        if (user==null) {
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().print("请先登录！");
            return false;
        }
        return true;
    }
}
